
class SimpleLRUCache:
	def __init__(self, max=10):
		self.max = max
		self.buffer = []

	def __getitem__(self, k):
		for i in range(len(self.buffer)):
			if self.buffer[i][0] == k:
				v = self.buffer[i][1]
				self.buffer.append(self.buffer.pop(i))
				return v

	def __setitem__(self, k, v):
		for i in range(len(self.buffer)):
			if self.buffer[i][0] == k:
				self.buffer.pop(i)
				self.buffer.append((k, v))
				return
		if len(self.buffer) >= self.max:
			self.buffer.pop(0)
		self.buffer.append((k, v))

if __name__ == '__main__':
	x = SimpleLRUCache(max=3)

	x[1] = 11
	x[2] = 12
	x[3] = 13
	x[4] = 14
	x[5] = 15
	x[1] = 11
	x[5] = 25

	print x[1]
	print x.buffer

